<template>
    <div style="width: 100%">
        <div style="width: 20%"><span>新密码：</span><div><el-input placeholder="请输入密码" v-model="input" show-password></el-input></div>
        </div>
        <div style="width: 20%;margin-top: 20px"><span>再次输入：</span><div><el-input placeholder="请再次输入" v-model="input1" show-password></el-input></div>
            <el-button type="primary" @click="goto" style="margin-top: 20px">确认修改</el-button>
        </div>
    </div>
</template>

<script>
    export default {
        name: "index",
        data(){
            return {
                input: '',
                input1: ''
            }
        },
        methods:{
            async goto(){
                if(this.input === '' && this.input === ''){
                    this.$message({
                        message: '请输入新密码',
                        type: 'info'
                    });
                    return;
                }
                if(this.input === ''){
                    this.$message({
                        message: '请输入新密码',
                        type: 'info'
                    });
                    return;
                }
                if(this.input1 === ''){
                    this.$message({
                        message: '请再次输入密码',
                        type: 'info'
                    });
                    return;
                }
                if (this.input !== this.input1) {
                    this.$message({
                        message: '两次输入的密码不一致,请重新输入!',
                        type: 'error'
                    });
                    return;
                }

                if(this.input === this.input1){
                    let res = await this.$http('updatePassword', {
                        password: this.input1
                    });
                    console.log(res)
                    this.$message({
                        message: '修改成功',
                        type: 'success'
                    });
                }
            }
        },
        mounted() {

        }
    }
</script>

<style scoped>

</style>
